﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jamhee.Noctiluca.Common
{
    public class AppUtil
    {
        public static readonly string WORK_ROOT = "$(workroot)";
        public static readonly string CONFIG_FILE_PATH = WORK_ROOT + "\\config";
        public static readonly string EXECUTION_FILE_PATH = WORK_ROOT + "\\bin";
        public static readonly string WEB_CONFIG_DEF_FILE = "web.def";

        public static string GetAbsolutePath(string path)
        {
            if (path.ToLower().Contains(WORK_ROOT))
            {
                string exePath = System.AppDomain.CurrentDomain.BaseDirectory;

                LogUtil.PrintInfo(exePath);



                // remove '\bin' at the end of the path
                string workroot = "";
                if (exePath.Length >= 4)
                {
                    workroot = exePath.Substring(0, exePath.Length - 4);
                }

                path = path.ToLower().Replace(WORK_ROOT, workroot);

                LogUtil.PrintInfo(path);
            }

            // Use Path.GetFullPath to avoid returning double slashes
            return System.IO.Path.GetFullPath(path);
        }
    }
}
